(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:AdminlayoutCtrl
     * @description
     * # AdminlayoutCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('AdminlayoutCtrl', AdminlayoutCtrl);

    AdminlayoutCtrl.$inject = ['$scope', 'dataService', '$timeout', '$location', 'helper', '$document', '$filter', '$state', '$rootScope', '$compile', ];


    function AdminlayoutCtrl($scope, dataService, $timeout, $location, helper, $document, $filter, $state, $rootScope, $compile) {


        //初始方法
        $scope.listAction = function() {
            $scope.getlist(1);
        }


        $scope.getlist = function(pageNo) {
            var query = {
                content: {
                    page_no: pageNo,
                    page_size: $scope.pageSize ? $scope.pageSize : 10,
                }
            };

            dataService.adminlayoutGet(query).then(function(list) {
                if (list) {
                    $scope.adminlayouts = list.adminlayouts;
                    $scope.total_count = list.total_count;
                }
            });
        }

        //删除
        $scope.delete = function(admin_layout_id) {
            if (admin_layout_id) {
                dataService.adminlayoutDel(admin_layout_id).then(function(li) {
                    if (li.Msg) {
                        helper.myAlert("error" + li.Msg);
                    } else {
                        helper.myAlert("success");
                        $scope.getlist(1);
                    }
                });
            } else {
                helper.myAlert("模板id不能为空");
            }


        }

        //获取体验二维码
        $scope.testQrCode = function(page, id) {
            $timeout(function() {
                var scence = "";
                return scence = "UICF" + id + "KEY" + page;

            }).then(function(scence) {
                dataService.acodeunlimitGet('wx04607907184215ec', scence, true, "pages/index/index").then(function(qrimage) {
                    $scope.qrimage = "data:image/png;base64," + qrimage;
                    var qrcodeWin = $.alert({
                        backdrop: "static",
                        keyboard: false,
                        title: '{{"请用微信扫描体验"|translate}}',
                        body: '<p style="text-align:center"><img ng-src="{{qrimage}}" width="240" /></p>',
                        okBtn: '{{"关闭"|translate}}',
                        closeBtn: true,
                        hasfoot: false,
                        transition: true,
                        width: 'small',
                        show: function(e) {
                            $compile($(e.currentTarget).contents())($scope);
                        },
                        okHide: function(e) {},
                        shown: function(e) {}
                    });
                });
            });
        }


    }
})();